package drds.binlog.deployer;

import drds.binlog.kafka.KafkaStarter;
import drds.binlog.server.ServerStarter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Properties;

/**
 * 独立版本启动的入口类
 */
public class Launcher
{


    private static final Logger logger = LoggerFactory.getLogger(Launcher.class);

    public static void main(String[] args) throws Throwable
    {
        try
        {


            Properties properties = new Properties();

            final Controller controller = new Controller(properties);
            controller.start();

            Runtime.getRuntime().addShutdownHook(new Thread()
            {

                public void run()
                {
                    try
                    {

                        controller.stop();
                    } catch (Throwable e)
                    {
                        logger.warn("##something goes wrong when stopping canal Server:", e);
                    } finally
                    {
                        logger.info("## canal server is down.");
                    }
                }

            });

            ServerStarter serverStarter = new KafkaStarter();
            serverStarter.init();

        } catch (Throwable e)
        {
            logger.error("## Something goes wrong when starting up the canal Server:", e);
            System.exit(0);
        }
    }


}
